import { Router } from 'express';
import { ConfigController } from '../controllers/configController';
import { authenticate } from '../middleware/auth';
import { getCategories, getOilTypes } from '../controllers/configController';

const router = Router();

/**
 * @swagger
 * tags:
 *   name: 系统配置
 *   description: 费用类型和系统参数管理
 */

// 车辆分类配置
router.get('/categories', authenticate, getCategories);

// 燃油类型配置
router.get('/oil-types', authenticate, getOilTypes);

// 费用类型
/**
 * @swagger
 * /api/config/expense-types:
 *   get:
 *     summary: 获取费用类型列表
 *     tags: [系统配置]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 成功
 */
router.get('/expense-types', authenticate, ConfigController.listExpenseTypes);

/**
 * @swagger
 * /api/config/expense-types:
 *   post:
 *     summary: 新增费用类型
 *     tags: [系统配置]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *               code:
 *                 type: string
 *               description:
 *                 type: string
 *     responses:
 *       201:
 *         description: 创建成功
 */
router.post('/expense-types', authenticate, ConfigController.createExpenseType);

/**
 * @swagger
 * /api/config/expense-types/{id}:
 *   put:
 *     summary: 修改费用类型
 *     tags: [系统配置]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *               description:
 *                 type: string
 *     responses:
 *       200:
 *         description: 修改成功
 */
router.put(
  '/expense-types/:id',
  authenticate,
  ConfigController.updateExpenseType
);

/**
 * @swagger
 * /api/config/expense-types/{id}:
 *   delete:
 *     summary: 删除费用类型
 *     tags: [系统配置]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: 删除成功
 */
router.delete(
  '/expense-types/:id',
  authenticate,
  ConfigController.deleteExpenseType
);

// 系统参数
/**
 * @swagger
 * /api/config/system-param:
 *   get:
 *     summary: 获取系统参数
 *     tags: [系统配置]
 *     parameters:
 *       - in: query
 *         name: key
 *         required: true
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: 成功
 */
router.get('/system-param', ConfigController.getSystemParam);

/**
 * @swagger
 * /api/config/system-param:
 *   post:
 *     summary: 设置系统参数
 *     tags: [系统配置]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               key:
 *                 type: string
 *               value:
 *                 type: string
 *               description:
 *                 type: string
 *     responses:
 *       200:
 *         description: 设置成功
 */
router.post('/system-param', ConfigController.setSystemParam);

export default router;
